<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            box-sizing: border-box;
        }
        body {
            margin: 0;
            padding: 0;
            font-family: "Ubuntu Mono", "Lucida Console", monospace;
            background-color: #333;
            color: #ddd;
            font-size: 14px;
        }
        .note {
            font-size: 80%;
            padding: 6px 0px;
            margin: 0;
        }
        .container {
            width: 100%;
            padding: 10px;
        }
        h1 {
            margin: 0;
            color: lawngreen;
        }
        h2 {
            margin: 10px 0px 0px;
            font-size: 140%;
            color: tomato;
        }
        h3 {
            margin: 16px 0px 0px;
            font-size: 120%;
            color: orange;
            border-bottom: 1px solid #444;
        }
        pre {
            margin: 0;
            padding: 0;
            font-size: 100%;
            width: 100%;
            line-height: 1.5rem;
            border: 0;
            overflow-x: auto;
            white-space: pre-wrap;
        }
        pre .com {
            color: #999;
            display: block;
        }
        pre .pln,
        pre .pun,
        pre .opn,
        pre .clo {
            color: #ddd;
        }
        pre .str {
            color: lawngreen;
        }
        pre .kwd {
            color: skyblue;
        }
        pre .typ {
            color: yellow;
        }
        pre .com + .pln {
            white-space: normal;
        }
        pre.prettyprint {
            border: 0 !important;
        }
        li.L1,
        li.L3,
        li.L5,
        li.L7,
        li.L9 {
            background: #3f3f3f !important;
        }
        ol.linenums,
        li {
            list-style-type: decimal-leading-zero !important;
        }
        .linenums li {
            border-left: 4px solid #555;
            padding-left: 10px;
        }
        ul {
            margin: 0;
            padding: 0;
            width: 100%;
            display: -webkit-box;
            display: -moz-box;
            display: -ms-flexbox;
            display: -webkit-flex;
            display: flex;
            -webkit-flex-direction: row;
            flex-direction: row;
            flex-wrap: wrap;
            -webkit-box-pack: flex-start;
            -moz-box-pack: flex-start;
            -ms-flex-pack: flex-start;
            -webkit-justify-content: flex-start;
            justify-content: flex-start;
            -webkit-box-align: flex-start;
            -moz-box-align: flex-start;
            -ms-flex-align: flex-start;
            -webkit-align-items: flex-start;
            align-items: flex-start;
            list-style-type: none;
        }
        ul.sheet > li {
            display: block;
            width: 100%;
        }
        @media only screen and (min-width: 800px) {
            body {
                font-size: 16px;
            }
            ul.sheet > li {
                width: 50%;
                padding: 0 10px;
            }
        }
        @media only screen and (min-width: 1200px) {
            ul.sheet > li {
                width: 33.33%;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <header>
        <h1>Git Cheatsheet</h1>
    </header>
    <p class="note">Note: Items contained in [] are optional. All caps words should be replaced, except HEAD.</p>

    <h2>Basics</h2>
    <ul class="sheet">
        <li>
            <h3>Just installed Git?</h3>
            <pre class="prettyprint lang-git">git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global color.ui true
git config --global core.autocrlf true</pre>
        </li>
        <li>
            <h3>Create</h3>
            <pre class="prettyprint lang-git"># From existing data
git init
git add .
git commit -m "Initial commit."
# From existing repo
git clone ~/existing ~/new
git clone https://USER@HOST.COM/PROJECT.git</pre>
        </li>
        <li>
            <h3>Browse</h3>
            <pre class="prettyprint lang-git"># View changed files
git status
# View changes
git diff [ID:FILE]
# View changes between commits
git diff ID1 ID2
# View History
git log
# Who did this?
git blame FILE
# View changes between branches
git diff branch1..branch2</pre>
        </li>
        <li>
            <h3>Update</h3>
            <pre class="prettyprint lang-git">git fetch [REMOTE BRANCH]
# Fetch and merge
git pull [REMOTE BRANCH]</pre>
        </li>
        <li>
            <h3>Local work</h3>
            <pre class="prettyprint lang-git"># Add all changes to stage
git add .
# Commit all tracked files
git commit -a [-m "Initial commit."]
# Commit staged changes
git commit
# Unstage file
git reset FILE</pre>
        </li>
        <li>
            <h3>Branch</h3>
            <pre class="prettyprint lang-git"># View branches
git branch
# Switch between branches
git checkout BRANCH
# Merge branches
git checkout BRANCH2
# Delete local branch
git branch -d BRANCH
# Delete without merging
git branch -D BRANCH
# Delete remote branch
git push REMOTE --delete BRANCH
# Fetch remote branch to local
git pull REMOTE REMOTE_BRANCH:LOCAL_BRANCH</pre>
        </li>
        <li>
            <h3>Stash</h3>
            <pre class="prettyprint lang-git"># Save a stash
git stash
# View stashes
git stash list
# Apply stash
git stash apply [STASH1]
# Apply and remove
git stash pop
# Clear all stashes
git stash clear</pre>
        </li>
        <li>
            <h3>Reset</h3>
            <pre class="prettyprint lang-git"># Revert to last commit
git reset --hard HEAD^
# Undo last commit
git reset --soft HEAD^
# Reset file
git checkout -- FILE</pre>
        </li>
        <li>
            <h3>Publish</h3>
            <pre class="prettyprint lang-git"># Push changes to another repo
git push [REMOTE BRANCH]
# Make a version or milestone
git tag NAME
</pre>
        </li>
        <li>
            <h3>Maintenance</h3>
            <pre class="prettyprint lang-git"># Remove untracked files and directories
git clean -fd
# Check for errors
git fsck</pre>
        </li>
        <li>
            <h3>Aliases</h3>
            <pre class="prettyprint lang-git"># Config format
git config --global alias.co "checkout"

co "checkout"
st "status -sb"
ls "log --pretty=format:'%h: %s'"
df "diff"
ci "commit"

# Usage
git co branch</pre>
        </li>
        <li>
            <h3>Archive</h3>
            <pre class="prettyprint lang-git"># Archive into a zip file
git archive --format zip --output /full/path/file.zip BRANCH</pre>
        </li>
    </ul>
    <h2>Advanced</h2>
    <ul class="sheet">
        <li>
            <h3>Amend commit</h3>
            <pre class="prettyprint lang-git">git commit -m "Initial commit."
git add FILE
git commit --amend</pre>
        </li>
        <li>
            <h3>Push to a different remote branch</h3>
            <pre class="prettyprint lang-git">git push REMOTE LOCAL_BRANCH:REMOTE_BRANCH</pre>
        </li>
        <li>
            <h3>Access new remote branch</h3>
            <pre class="prettyprint lang-git">git fetch REMOTE REMOTE_BRANCH:LOCAL_BRANCH
git checkout LOCAL_BRANCH</pre>
        </li>
        <li>
            <h3>Set upstream</h3>
            <pre class="prettyprint lang-git">git branch --set-upstream BRANCH REMOTE/REMOTE_BRANCH</pre>
        </li>
        <li>
            <h3>Files</h3>
            <pre class="prettyprint lang-git"># Untrack file without removing
git rm --cached FILE
# Untrack folder without removing
git rm -r --cached FOLDER/.
</pre>
        </li>
        <li>
            <h3>Changes</h3>
            <pre class="prettyprint lang-git"># Ignore file mode changes
git config core.fileMode false
</pre>
        </li>
    </ul>
</div>
</body>
</html>

<script>
    PR['registerLangHandler'](
            PR['createSimpleLexer'](
                    [
                        // Whitespace
                        [PR['PR_PLAIN'], /^[\t\n\r \xA0]+/, null, '\t\n\r \xA0'],
                        // A double or single quoted, possibly multi-line, string.
                        [PR['PR_STRING'], /^(?:"(?:[^\"\\]|\\.)*"|'(?:[^\'\\]|\\.)*')/, null,
                            '"\''
                        ]
                    ], [
                        // A comment is either a line comment that starts with two dashes, or
                        // two dashes preceding a long bracketed block.
                        [PR['PR_COMMENT'], /^(?:#[^\r\n]*)/],
                        [PR['PR_KEYWORD'], /\b(?:git|list|branch|config|init|clone|status|archive|diff|add|commit|push|pull|stash|remote|apply|pop|reset|clean|fetch|HEAD|clear|tag|checkout|rm|log|blame)\b/, null],
                        // An identifier
                        [PR['PR_PLAIN'], /^[a-z_][\w-]*/i],
                        // A run of punctuation
                        [PR['PR_PUNCTUATION'], /^[^\w\t\n\r \xA0\"\'][^\w\t\n\r \xA0+\-\"\']*/]
                    ]), ['git']);
</script>